misc
Class ScoreKeeper<A>

java.lang.Object
  extended by misc.ScoreKeeper<A>
Type Parameters:
A - key of the hashmap, for example a Value-object
All Implemented Interfaces:
java.io.Serializable, java.util.Comparator<A>

public class ScoreKeeper<A>
extends java.lang.Object
implements java.util.Comparator<A>, java.io.Serializable

Simple class which can be used to keep track of the score of a set of objects. An example of using this class is to count how many times a set of values has been offered by the opponent.

Author:
Tim Baarslag, Mark Hendrikx
See Also:
Serialized Form

Field Summary
protected  java.util.Map<A,java.lang.Integer> m
          Map of objects and their score
protected  int max
          The highest score in the map
protected  int total
          The sum of all scores in the map
 
Constructor Summary
ScoreKeeper()
          Creates a ScoreKeeper object by initializing the hashmap.
ScoreKeeper(ScoreKeeper<A> sk)
          Clones the given scorekeeper-object.
 
Method Summary
 int compare(A o1, A o2)
          Comparator to compare the score of two objects.
 java.util.Set<A> getElements()
          Returns the objects from which the score is registered.
 int getMaxValue()
          Returns the highest score in the map.
 double getNormalizedScore(A a)
          Returns the normalized score of the given object.
 double getRelativeScore(A a)
          Returns the relative score of a given object.
 int getScore(A a)
          Returns the score of the given object.
 java.util.TreeMap<A,java.lang.Integer> getSortedCopy()
           
 int getTotal()
          Returns the sum of all scores.
 void score(A a)
          Adds one to the score of the given object.
 void score(A a, int score)
          Method used to add a given score to a given object.
 java.lang.String toMathematicaListPlot()
          Returns a Mathematica list plot of the map.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Field Detail

m

protected java.util.Map<A,java.lang.Integer> m
Map of objects and their score


max

protected int max
The highest score in the map


total

protected int total
The sum of all scores in the map

Constructor Detail

ScoreKeeper

public ScoreKeeper()
Creates a ScoreKeeper object by initializing the hashmap.


ScoreKeeper

public ScoreKeeper(ScoreKeeper<A> sk)
Clones the given scorekeeper-object.

Parameters:
sk - object keeper which is cloned.
Method Detail

score

public void score(A a)
Adds one to the score of the given object.

Parameters:
a - object to which one must be added to its score.

score

public void score(A a,
                  int score)
Method used to add a given score to a given object.

Parameters:
a - object to which the given score must be added.
score - to be added to the object.

getScore

public int getScore(A a)
Returns the score of the given object.

Parameters:
a - object from which the score must be returned.
Returns:
score of the object.

getNormalizedScore

public double getNormalizedScore(A a)
Returns the normalized score of the given object. The normalized score is defined as the score divided by the highest score in the map.

Parameters:
a - the object from which the score is requested.
Returns:
score of the object divided by the highest score.

getRelativeScore

public double getRelativeScore(A a)
Returns the relative score of a given object. The relative score is the score of the object divided by the sum of all scores in the map.

Parameters:
a - object from which the score must be returned
Returns:
score of the object divided by the sum of all scores

compare

public int compare(A o1,
                   A o2)
Comparator to compare the score of two objects.

Specified by:
compare in interface java.util.Comparator<A>
Returns:
-1 iff score o1 > o2, 1 if vice versa, else 0.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
string representation of the ScoreKeeper.

getSortedCopy

public java.util.TreeMap<A,java.lang.Integer> getSortedCopy()
Returns:
sorted version of the ScoreKeeper based on the score of the elements.

getMaxValue

public int getMaxValue()
Returns the highest score in the map.

Returns:
score of the object with the highest score.

getTotal

public int getTotal()
Returns the sum of all scores.

Returns:
sum of all scores

getElements

public java.util.Set<A> getElements()
Returns the objects from which the score is registered.

Returns:
objects in the scoring map

toMathematicaListPlot

public java.lang.String toMathematicaListPlot()
Returns a Mathematica list plot of the map.

Returns:
Mathematica list plot of the map.